package com.jamal2362.apktool.util;

import android.content.Intent;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class TraceReader {
	private AppCompatActivity activity;

	public TraceReader(AppCompatActivity act) {
		this.activity = act;
	}

	public String readToString() {
		String trace = "";
		String  line;
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(activity.openFileInput("stack.trace")));
			while ((line = reader.readLine()) != null) {
				trace += line + "\n";
			}
		} catch (Exception e) {
			trace += e.getMessage();
		}
		return trace;
	}

	public void sendLog() {
		Toast.makeText(activity, "Send a log to the developer!", Toast.LENGTH_LONG).show();
		final Intent email = new Intent(android.content.Intent.ACTION_SEND);
        email.setType("plain/text");
        // email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "admin@diarys.tk" });
        // email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Apktool M Crashlog");
        email.putExtra(android.content.Intent.EXTRA_TEXT, readToString());
        activity.startActivity(Intent.createChooser(email, "Save Crash Log"));
	}
}
